<?php if(!defined('CALL')) exit('No direct script access allowed');

include_once('ctrl/page.class.php');
include_once('view/v_usercard.class.php');
include_once('view/v_menus.class.php');
include_once('view/v_users.class.php');
include_once('view/v_messages.class.php');
include_once('view/v_plans.class.php');
include_once('models/m_user.class.php');
include_once('models/m_events.class.php');
include_once('models/m_search.class.php');

class PageSearch extends Page
{
	private $results = null;
	private $str = '';
	
	public function __construct($actor, $find_str)
	{
		$this->str = $find_str;
		parent::__construct($actor, null);
		$this->page_name = "search";
		$this->prepare();
	}
	
	private function prepare()
	{
		// $this->actor->load_messages($this->user->id);
	}
	
	protected function gen_main()
	{
		$html = '';
		$this->results = mSearch::get_users($this->str);
		if(count($this->results) > 0)
		{
			$uids = implode(',', $this->results);
			$this->results = mUser::get_props($uids, TRUE);
		}
		Logger::Write(__FILE__." ".__FUNCTION__." line: ".__LINE__, print_r($this->results, true));
		$html .= vUsers::buildSimpleList('Кого нашли', $this->results);
		
		$this->results = mSearch::get_events($this->str, $this->actor);
		if(count($this->results) > 0)
		{
			$html .= '<h2>Какие события нашли</h2>';
		}
		$html .= vPlans::build_eventLine($this->results, $this->actor->id, TRUE);
		
		return $html;
	}

	protected function gen_side()
	{
		$html = '';
		
		$menus = new vMenus();
		$html .= $menus->gen_search_form();
		
		if($this->user->id)
			$html .= $menus->gen_calendar_holder();
			
		return $html;
	}

	protected function add_css()
	{
		return "";
	}

	protected function add_css_files()
	{
		return "";
	}

	protected function add_js()
	{
		return "";
	}

	protected function add_js_files()
	{
		$js_names = array("EventProcessor");
		$js = "";
		foreach($js_names as $name)
			$js .= "\t".'<script type="text/javascript" src="'.ROOT_URL.'/js/'.$name.'.js"></script>'."\n";
		return $js;
	}
}
